package techquest{
   //Imports here
	import techquest.Velocity;


   public class Physics {

      public static const GRAVITY:Number = 9.81;
	private static const LAUNCH_TIME:Number = 0.5;
      
      public function Physics() {

      }

      public function getChangeInXDistance( velocityX:Number, changeInTime:Number ):Number {
         return velocityX * changeInTime;
      }

      public function getChangeInYDistance( velocityY:Number, changeInTime:Number ):Number {
         return velocityY * changeInTime + 0.5 * GRAVITY * (changeInTime * changeInTime);
      }
   
      // always takes .5 seconds to leave the slingshot
	// ignoring gravity on the launch, assuming that the angle and force is the only force on the object at launch
      public function getInitialVelocities( force:Number, mass:Number, angle:Number ):Velocity {
         // force, mass, force direction 
         // so with the angle I should be able to separate the forces into the forces in the x and y vectors
         // once I have this I can accellerate the balloon over the .5 second throw

	var forceX:Number;
	var forceY:Number;
	var quadrentAngle:Number;
	var velocity:Velocity = new Velocity();

	 if( angle == 0 ){
		forceX = 0;
		forceY = force;
	} else if( angle == Math.PI / 2 ) {
		forceX = force;
		forceY = 0;
	} else if( angle == Math.PI ) {
		forceX = 0;
		forceY = -force;
	} else if( angle == ( 3 * Math.PI ) / 2 ) {
		forceX = -force;
		forceY = 0;
	} else {
		if( angle > 0 && angle < Math.PI ) {
			quadrentAngle = Math.abs( angle - Math.PI / 2 );
		} else if( angle > Math.PI && angle < 2 * Math.PI ) {
			quadrentAngle = Math.abs( angle - ( 3 * Math.PI ) / 2 );
		}

         	forceX = force * Math.sin( quadrentAngle );
         	forceY = force * Math.cos( quadrentAngle );
	}
	velocity.velocityX = ( forceX / mass ) * LAUNCH_TIME;
	velocity.velocityY = ( forceY / mass ) * LAUNCH_TIME;
	return velocity;
      }

      public function updateYVelocity( velocityY:Number, changeInTime:Number ):Number {
         return velocityY + ( GRAVITY * changeInTime );
      }
      
   }
}

